﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ECommerce.BLL.Advertisement;
using ECommerce.Model.Advertisement;
using Jzy.Core.Utility;

namespace ECommerce.Web.ECAdmin.Advertisement
{
    public partial class Edit : PageEdit
    {
        private AdvertisementBO Ad
        {
            get
            {
                return AdvertisementBO.Instance<AdvertisementBO>();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(this.PKID))
                {
                    DispInfo();
                }
            }
        }
        private void DispInfo()
        {
            AdvertisementInfo info = Ad.GetInfo(this.PKID);

            this.txtName.Text = info.Name;
            this.txtHref.Text = info.Href;
            this.txtDescription.Text = info.Description;
            

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            AdvertisementInfo info = Ad.GetInfo(this.PKID);
            info.Name = txtName.Text;
            info.Href = txtHref.Text;
            info.Description = txtDescription.Text;
            if (fileImage.FileName != "")
            {
                if (!string.IsNullOrEmpty(info.SmallImage))
                {
                    this.Ad.DeleteImage(info.ID);
                }

                this.Ad.SaveImage(info, fileImage.PostedFile);
            }
            this.Ad.Save(info);
            JSUtil.RefreshView();
        }
    }
}